﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Entity;
using IRepository;
using IService;

namespace Service
{
    public class PublicAttachmentsService:IPublicAttachmentsService
    {
        private readonly IPublicAttachmentsRepository _repository;

        public PublicAttachmentsService(IPublicAttachmentsRepository repository)
        {
            _repository = repository;
        }

        /// <summary>
        /// 实现新增附件业务逻辑
        /// </summary>
        /// <param name="attachment"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentException"></exception>
        public async Task AddAsync(SysOrgPublicAttachments attachment)
        {
            // 业务校验（示例：检查附件路径是否为空）
            if (string.IsNullOrWhiteSpace(attachment.upload_image))
            {
                throw new ArgumentException("附件路径不能为空");
            }

            await _repository.AddAsync(attachment);
        }

        public async Task<List<SysOrgPublicAttachments>> GetByAnnexCodeAsync(string annexCode)
        {
            // 业务校验：附件编号不能为空
            if (string.IsNullOrEmpty(annexCode))
            {
                throw new ArgumentException("附件编号不能为空");
            }

            return await _repository.GetByAnnexCodeAsync(annexCode);
        }
    }
}
